package com.example.lib_core.mvp.view;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.lib_core.init.Core;
import com.example.lib_core.mvp.presenter.IPresenter;
import com.tbruyelle.rxpermissions2.RxPermissions;

public abstract class BaseActivty<P extends IPresenter> extends AppCompatActivity implements IView,IActivity {
    protected P mPresenter;
    private RxPermissions rxPermissions;
    //提供权限申请
    public RxPermissions getRxPermissions() {
        if(rxPermissions==null){
            rxPermissions=new RxPermissions(this);
        }
        return rxPermissions;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bondLayout());
        initView();
        inject();
        initData();
    }

    @Override
    public void Toast(String string) {
        Toast.makeText(Core.getInstance().getApplication(), ""+string, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mPresenter!=null){
            mPresenter.onDestroy();
            mPresenter=null;
        }
    }
}
